package edu.base.service;

import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.base.dao.CatDetailMapper;
import edu.base.model.CatDetail;
import edu.base.model.Statistics;

@Service
public class CatDetailService {

	@Autowired
	CatDetailMapper catDetailMapper;
	
	
	public Integer insert(CatDetail item) {
		return catDetailMapper.insertSelective(item);
	}
	
	public void del(Integer id) {
		catDetailMapper.deleteByPrimaryKey(id);
	}
	
	public void update(CatDetail item) {
		catDetailMapper.updateByPrimaryKeySelective(item);
	}
	
	public CatDetail findByKey(Integer key) {
		return catDetailMapper.selectByPrimaryKey(key);
	}
	
	public List<CatDetail> find(Integer catId, Integer state, Boolean guoqi, Integer toId){
		return catDetailMapper.query(catId, state, guoqi, toId);
	}
	
	public Integer count(Integer catId,Integer state, Boolean guoqi,Integer toId) {
		return catDetailMapper.count(catId, state, guoqi, toId);
	}
	
	public List<CatDetail> find2(String formType,Integer catId, Integer state, Boolean guoqi, Integer toId,Integer p, Integer size){
		if(p == null) {
			p = 1;
		}
		if(formType != null && formType.length() > 0) {
			formType = "%" + formType + "%";
		}else {
			formType = null;
		}
		return catDetailMapper.query2(formType,catId, state, guoqi, toId,(p-1)*size, size);
	}
	
	public Integer count2(String formType,Integer catId, Integer state, Boolean guoqi, Integer toId) {
		return catDetailMapper.count2(formType, catId, state, guoqi, toId);
	}
	
	
	public List<Statistics> stat(Integer year){
		return catDetailMapper.stat(year);
	}
	
}
